package iut.acy.cut4u.model;



import java.text.DateFormat;
import java.text.ParseException;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Calendar;
import java.util.Locale;

public class GregorianDateString {

         public static DateFormat formatDateFrance = DateFormat.getDateInstance(DateFormat.SHORT, Locale.FRANCE);
         public static DateFormat formatDateUs = DateFormat.getDateInstance(DateFormat.SHORT, Locale.US);
         
         public static String gregorianToStringFormatFrance(GregorianCalendar gdate)
        {
                String str =GregorianDateString.formatDateFrance.format(gdate.getTime());
                return str;
        }
         

         public static String gregorianToStringFormatUS(GregorianCalendar gdate)
        {
               
                return gdate.get(Calendar.YEAR)+"-"+
                                gdate.get(Calendar.MONTH)+"-"+
                                gdate.get(Calendar.DAY_OF_MONTH);
        }
         
         public static GregorianCalendar formatFranceToGregorianCalendar(String sdate)
                {
              if ( sdate ==null)
                  return null;
              if( sdate.equals(""))
                  return null;
           
              GregorianCalendar gdate =new GregorianCalendar();
             boolean dateOK= false ;
             Date date;
              try {
                    date = GregorianDateString.formatDateFrance.parse(sdate);
                    gdate.setTime(date);
                    dateOK = true ;
               } catch (ParseException e) {
               
                System.out.println (e);
                }
               if ( dateOK ==true)
                   return gdate;
                else
                        return null;
                }
               
}
